#ifndef COMMON_H_
#define COMMON_H_

#include "types.h"

/*********************************************************************************************************
  RISC-V 处理器 I/O 内存读
*********************************************************************************************************/

static inline u8 read8(u64 addr)
{
    u8 val = *(volatile u8 *)addr;
    return val;
}

static inline u16 read16(u64 addr)
{
    u16 val = *(volatile u16 *)addr;
    return val;
}

static inline u32 read32(u64 addr)
{
    u32 val = *(volatile u32 *)addr;
    return val;
}

static inline u64 read64(u64 addr)
{
    u64 val = *(volatile u64 *)addr;
    return val;
}

/*********************************************************************************************************
  RISC-V 处理器 I/O 内存写
*********************************************************************************************************/

static inline void write8(u8 val, u64 addr)
{
    *(volatile u8 *)addr = val;
}

static inline void write16(u16 val, u64 addr)
{
    *(volatile u16 *)addr = val;
}

static inline void write32(u32 val, u64 addr)
{
    *(volatile u32 *)addr = val;
}

static inline void write64(u64 val, u64 addr)
{
    *(volatile u64 *)addr = val;
}

#endif /* COMMON_H_ */
